//
//  LGMedicineBallHomeController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/22.
//

#import "LGMedicineBallHomeController.h"
//搜索
#import "LGMedicineBallSearchController.h"
//详情
#import "LGMedicineBallDetailController.h"
//添加患者
#import "LGMedicineBallAddController.h"
//发送短信提醒
#import "LGMedicineBallSMSController.h"
//更新入院进展
#import "LGMedicineBallPlanController.h"
#import "LGMedicineBallHeaderView.h"
#import "LGMedicineBallScreenView.h"
#import "LGMedicineBallPatientCell.h"
@interface LGMedicineBallHomeController ()<UITableViewDataSource,UITableViewDelegate,LGMedicineBallHeaderDelegate,LGMedicineBallPatientDelegate>
/**   */
@property (nonatomic , strong)LGMedicineBallHeaderView *headerView;
/**   */
@property (nonatomic , strong)LGMedicineBallScreenView *screenView;
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)UIView *bottomView;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)NSMutableDictionary *screenDic;
/**   */
@property (nonatomic , strong)NSMutableArray *dataArray;
/**   */
@property (nonatomic , strong)NSMutableArray *selectArray;

/**   */
@property (nonatomic , copy)NSString *pageNo;
/**  是否进入编辑状态 */
@property (nonatomic , assign)BOOL editing;

@end

@implementation LGMedicineBallHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.fd_prefersNavigationBarHidden = YES;
    self.screenDic = [NSMutableDictionary dictionary];
    self.view.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
    [self createNavigationView];
    [self.view addSubview:self.tableView];
    [self createBottomView];
    [self emptyViewWithSuperView:self.tableView frame:CGRectMake(0, 0, Screen_W, self.tableView.bounds.size.height)];
    self.emptyView.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
    [[UIApplication sharedApplication].keyWindow addSubview:self.screenView];
    [self requestScreenData];
    [self requestData];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshDataAction) name:@"refreshMedicinBallData" object:nil];
}

-(void)refreshDataAction{
    [self requestData];
    [self requestScreenData];
    if(self.headerView.batchBtn.selected == YES){
        [self batchBtnAction:self.headerView.batchBtn];
    }
    [self.selectArray removeAllObjects];
}

-(void)requestData{
    self.pageNo = @"1";
    self.dataArray = [NSMutableArray array];
    [self requestMoreData];
}

-(void)requestMoreData{
    [self.screenDic setValue:self.pageNo forKey:@"pageNo"];
    [self.screenDic setValue:@"20" forKey:@"pageSize"];
    [self.screenDic setValue:self.datasource forKey:@"datasource"];
    [RequestUtil withPOST:@"/doctor/patient.dcb.patient/pagedList" parameters:self.screenDic withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        if(code == 200){
            self.headerView.totalCount = LGNSString(returnData[@"total"]);
            NSArray *tempArray = returnData[@"data"];
            if(tempArray.count>0){
                self.pageNo = [NSString stringWithFormat:@"%ld",[returnData[@"current_page"] integerValue]+1];
                [self.dataArray addObjectsFromArray:tempArray];
            }else{
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
        [self.tableView reloadData];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    }];
}

-(void)requestScreenData{
    [RequestUtil withPOST:@"/doctor/patient.dcb.patient/filter" parameters:@{@"datasource":self.datasource} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            self.screenView.dataDic = returnData;
        }
    } error:^(NSError *error) {
        
    }];
}

//搜索患者
-(void)searchPatientAction{
    LGMedicineBallSearchController *controller = [[LGMedicineBallSearchController alloc]init];
    controller.datasource = self.datasource;
    [self.navigationController pushViewController:controller animated:YES];
}

//添加患者
-(void)addPatientAction{
    LGMedicineBallAddController *controller = [[LGMedicineBallAddController alloc]init];
    [self.navigationController pushViewController:controller animated:YES];
    __weak typeof(self) weakSelf = self;
    controller.addPatientSuccess = ^{
        [weakSelf requestData];
    };
}

//批量管理
-(void)batchBtnAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    CGFloat width = (sender.selected == YES)?viewPix(50):viewPix(80);
    [self.headerView.batchBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
    self.headerView.batchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.headerView.batchBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:5];
    [self performSelector:@selector(resetBatchButton) withObject:nil afterDelay:0.1];
    self.editing = sender.selected;
    [self.tableView reloadData];
    
    if(sender.selected ==  YES){
        //选择
        [UIView animateWithDuration:0.4 animations:^{
            self.tableView.frame = CGRectMake(0, topBarHeight+viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44)-viewPix(112));
            self.bottomView.frame = CGRectMake(0, kMaxY(self.tableView.frame), Screen_W, viewPix(112));
        }];
    }else{
        //取消选择
        [UIView animateWithDuration:0.4 animations:^{
            self.tableView.frame = CGRectMake(0, topBarHeight+viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44));
            self.bottomView.frame = CGRectMake(0, kMaxY(self.tableView.frame), Screen_W, viewPix(112));
        }];
    }
}

-(void)resetBatchButton{
    self.headerView.batchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.headerView.batchBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:5];
}

//发送短信提醒
-(void)sendSmsCodeAction{
    NSString *planids = @"";
    for (NSDictionary *tempDic in self.selectArray) {
        planids = (planids.length>0)?[NSString stringWithFormat:@"%@,%@",planids,tempDic[@"plan_id"]]:LGNSString(tempDic[@"plan_id"]);
    }
    if(planids.length>0){
        LGMedicineBallSMSController *controller = [[LGMedicineBallSMSController alloc]init];
        controller.planids = planids;
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        [TooltipView showMessage:@"请选择患者" offset:0];
    }
    
}

//更新入院进展
-(void)updateStatusAction{
    NSString *planids = @"";
    for (NSDictionary *tempDic in self.selectArray) {
        planids = (planids.length>0)?[NSString stringWithFormat:@"%@,%@",planids,tempDic[@"plan_id"]]:LGNSString(tempDic[@"plan_id"]);
    }
    if(planids.length>0){
        LGMedicineBallPlanController *controller = [[LGMedicineBallPlanController alloc]init];
        controller.planids = planids;
        controller.hiddenRemark = YES;
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        [TooltipView showMessage:@"请选择患者" offset:0];
    }
    
}

//展开筛选View
-(void)showScreenViewAnimation{
    [self.screenView showScreenViewAnimation];
}

//重置筛选
-(void)resetScreenAction{
    self.screenDic = [NSMutableDictionary dictionary];
    [self.screenView resetDataAction];
    [self.screenView closeViewAction];
    self.headerView.dataDic = @{};
    [self requestData];
}

//删除筛查选项
-(void)deleteScreenItem:(NSDictionary *)itemDic{
    NSString *key = LGNSString(itemDic[@"key"]);
    NSString *content = LGNSString(itemDic[@"title"]);
    if([key isEqualToString:@"plan_date_full"]){
        self.screenView.plan_date_start = @"";
        self.screenView.plan_date_end = @"";
        [self.screenDic removeObjectForKey:@"plan_date_start"];
        [self.screenDic removeObjectForKey:@"plan_date_end"];
        
    }else if ([key isEqualToString:@"plan_date_start"]){
        self.screenView.plan_date_start = @"";
        [self.screenDic removeObjectForKey:@"plan_date_start"];
     
    }else if ([key isEqualToString:@"plan_date_end"]){
        self.screenView.plan_date_end = @"";
        [self.screenDic removeObjectForKey:@"plan_date_end"];
        
    }else if ([key isEqualToString:@"appointment_date_full"]){
        self.screenView.appointment_date_start = @"";
        self.screenView.appointment_date_end = @"";
        [self.screenDic removeObjectForKey:@"appointment_date_start"];
        [self.screenDic removeObjectForKey:@"appointment_date_end"];
        
    }else if ([key isEqualToString:@"appointment_date_start"]){
        self.screenView.appointment_date_start = @"";
        [self.screenDic removeObjectForKey:@"appointment_date_start"];
        
    }else if ([key isEqualToString:@"appointment_date_end"]){
        self.screenView.appointment_date_end = @"";
        [self.screenDic removeObjectForKey:@"appointment_date_end"];
        
    }else{
        if([self.screenView.screenDic.allKeys containsObject:key]){
            NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:self.screenView.screenDic[key]];
            if([tempDic.allKeys containsObject:content]){
                [tempDic removeObjectForKey:content];
            }
            [self.screenView.screenDic setValue:tempDic forKey:key];
        }
    }
    
    [self.screenView.collectionView reloadData];
    [self sureScreenAction];
}

//确定筛选
-(void)sureScreenAction{
    self.screenDic = [NSMutableDictionary dictionary];
    NSArray *keyArray = self.screenView.screenDic.allKeys;
    for (NSInteger i=0; i<keyArray.count; i++) {
        NSDictionary *tempDic = self.screenView.screenDic[keyArray[i]];
        NSArray *valueArray = tempDic.allValues;
        if(valueArray.count>0){
            NSString *reslut = LGNSString(valueArray[0]);
            for (NSInteger j=1; j<valueArray.count; j++) {
                reslut = [NSString stringWithFormat:@"%@,%@",reslut,valueArray[j]];
            }
            [self.screenDic setValue:reslut forKey:keyArray[i]];
        }
    }
    [self.screenDic setValue:self.screenView.plan_date_start forKey:@"plan_date_start"];
    [self.screenDic setValue:self.screenView.plan_date_end forKey:@"plan_date_end"];
    [self.screenDic setValue:self.screenView.appointment_date_start forKey:@"appointment_date_start"];
    [self.screenDic setValue:self.screenView.appointment_date_end forKey:@"appointment_date_end"];
    [self requestData];
    NSMutableDictionary *headDic = [NSMutableDictionary dictionaryWithDictionary:self.screenView.screenDic];
    if(self.screenView.plan_date_start.length>0 && self.screenView.plan_date_end.length>0){
        NSString *string = [NSString stringWithFormat:@"%@-%@",self.screenView.plan_date_start,self.screenView.plan_date_end];
        [headDic setValue:@{string:string} forKey:@"plan_date_full"];
    }else if (self.screenView.plan_date_start.length>0){
        NSString *string = [NSString stringWithFormat:@"%@",self.screenView.plan_date_start];
        [headDic setValue:@{string:string} forKey:@"plan_date_start"];
    }else if (self.screenView.plan_date_end.length>0){
        NSString *string = [NSString stringWithFormat:@"%@",self.screenView.plan_date_end];
        [headDic setValue:@{string:string} forKey:@"plan_date_end"];
    }
    
    if(self.screenView.appointment_date_start.length>0 && self.screenView.appointment_date_end.length>0){
        NSString *string = [NSString stringWithFormat:@"%@-%@",self.screenView.appointment_date_start,self.screenView.appointment_date_end];
        [headDic setValue:@{string:string} forKey:@"appointment_date_full"];
        
    }else if (self.screenView.appointment_date_start.length>0){
        NSString *string = [NSString stringWithFormat:@"%@",self.screenView.appointment_date_start];
        [headDic setValue:@{string:string} forKey:@"appointment_date_start"];
    }else if (self.screenView.appointment_date_end.length>0){
        NSString *string = [NSString stringWithFormat:@"%@",self.screenView.appointment_date_end];
        [headDic setValue:@{string:string} forKey:@"appointment_date_end"];
    }
    self.headerView.dataDic = headDic;
    [self.screenView closeViewAction];
}

//headView高度变化
-(void)headViewHeightChanged:(CGFloat)height{
    self.headerView.frame = CGRectMake(0, 0, Screen_W, height);
    self.tableView.tableHeaderView = self.headerView;
    self.emptyView.frame = CGRectMake(0, height, Screen_W, self.tableView.bounds.size.height-height);
}

//忽略
-(void)ignoreDataAction:(NSString *)planid index:(NSInteger)index{
    __block NSInteger currentIndex = index;
    [RequestUtil withPOST:@"/doctor/patient.dcb.patient/ignore" parameters:@{@"plan_id":planid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            [self.dataArray removeObjectAtIndex:currentIndex];
            [self.tableView reloadData];
        }else{
            [TooltipView showMessage:message offset:0];
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:@"忽略失败，请重试" offset:0];
    }];
}

//选中
-(void)selectPlan:(BOOL)selected index:(NSInteger)index{
    NSDictionary *tempDic = self.dataArray[index];
    if(selected == YES){
        [self.selectArray addObject:tempDic];
    }else{
        [self.selectArray removeObject:tempDic];
    }
    [self.tableView reloadData];
    NSString *number = [NSString stringWithFormat:@"%ld",self.selectArray.count];
    NSString *content = [NSString stringWithFormat:@"已选 %@ 人",number];
    self.numberLabel.attributedText = [content attributeString:@{NSFontAttributeName:LGFontWeight(15, UIFontWeightMedium),NSForegroundColorAttributeName:[UIColor colorWithString:@"#3291FF"]} range:NSMakeRange(3, number.length)];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGMedicineBallPatientCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    cell.dataDic = tempDic;
    cell.index = indexPath.row;
    cell.isEditing = self.editing;
    cell.delegate = self;
    cell.selectBtn.selected = [self.selectArray containsObject:tempDic]?YES:NO;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    LGMedicineBallDetailController *controller = [[LGMedicineBallDetailController alloc] init];
    controller.operatName = LGNSString(tempDic[@"plan_type_name"]);
    controller.planType = LGNSString(tempDic[@"type"]);
    controller.planid = LGNSString(tempDic[@"plan_id"]);
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark
#pragma mark ====> 创建控件
-(NSMutableArray *)dataArray{
    if(!_dataArray){
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

-(NSMutableArray *)selectArray{
    if(!_selectArray){
        _selectArray = [NSMutableArray array];
    }
    return _selectArray;
}
-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, topBarHeight+viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44)) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGMedicineBallPatientCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.headerView;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestData)];
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestMoreData)];
    }
    return _tableView;
}

-(LGMedicineBallHeaderView *)headerView{
    if(!_headerView){
        _headerView = [[LGMedicineBallHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(45))];
        [_headerView.screenBtn addTarget:self action:@selector(showScreenViewAnimation) forControlEvents:UIControlEventTouchUpInside];
        [_headerView.batchBtn addTarget:self action:@selector(batchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_headerView.addBtn addTarget:self action:@selector(addPatientAction) forControlEvents:UIControlEventTouchUpInside];
        _headerView.type = self.datasource;
        _headerView.delegate = self;
    }
    return _headerView;
}

-(LGMedicineBallScreenView *)screenView{
    if(!_screenView){
        _screenView = [[LGMedicineBallScreenView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        [_screenView.resetBtn addTarget:self action:@selector(resetScreenAction) forControlEvents:UIControlEventTouchUpInside];
        [_screenView.sureBtn addTarget:self action:@selector(sureScreenAction) forControlEvents:UIControlEventTouchUpInside];
        _screenView.hidden = YES;
    }
    return _screenView;
}

-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(112))];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
        _numberLabel.frame = CGRectMake(viewPix(16), viewPix(10), viewPix(200), viewPix(20));
        _numberLabel.attributedText = [@"已选 0 人" attributeString:@{NSFontAttributeName:LGFontWeight(15, UIFontWeightMedium),NSForegroundColorAttributeName:[UIColor colorWithString:@"#3291FF"]} range:NSMakeRange(3, 1)];
    }
    return _numberLabel;
}

-(void)createBottomView{
    [self.view addSubview:self.bottomView];
    [self.bottomView addSubview:self.numberLabel];
    UIButton *smsBtn = [UIButton buttonWithTitle:@"发送短信提醒" titleFont:LGFontWeight(16, UIFontWeightMedium) normalColor:@"#429BFF" selectColor:@"#429BFF"];
    smsBtn.frame = CGRectMake(viewPix(16), viewPix(40), (Screen_W-viewPix(40))/2.0, viewPix(46));
    smsBtn.layer.borderColor = [UIColor colorWithString:@"#429BFF"].CGColor;
    smsBtn.layer.borderWidth = 1;
    smsBtn.cornerRidus = 10;
    [smsBtn addTarget:self action:@selector(sendSmsCodeAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:smsBtn];
    UIButton *updateBtn = [UIButton buttonWithTitle:@"更新入院进展" titleFont:LGFontWeight(16, UIFontWeightMedium) normalColor:@"#429BFF" selectColor:@"#429BFF"];
    updateBtn.frame = CGRectMake(kMaxX(smsBtn.frame)+viewPix(8), viewPix(40), (Screen_W-viewPix(40))/2.0, viewPix(46));
    updateBtn.layer.borderColor = [UIColor colorWithString:@"#429BFF"].CGColor;
    updateBtn.layer.borderWidth = 1;
    updateBtn.cornerRidus = 10;
    [updateBtn addTarget:self action:@selector(updateStatusAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:updateBtn];
}

-(void)createNavigationView{
    UIView *baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, topBarHeight+viewPix(44))];
    baseView.backgroundColor = [UIColor colorWithString:@"#E5F3FF"];
    [self.view addSubview:baseView];
    CAGradientLayer *gradLayer = [[CAGradientLayer alloc]init];
    gradLayer.frame = CGRectMake(0, topBarHeight, Screen_W ,viewPix(44));
    gradLayer.startPoint = CGPointMake(0.5, 0);
    gradLayer.endPoint = CGPointMake(0.5, 1.0);
    gradLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E5F3FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F9FE"].CGColor, (__bridge id)[UIColor colorWithString:@"#FEFEFF"].CGColor];
    gradLayer.locations = @[@(0), @(0.6), @(1.0f)];
    [baseView.layer addSublayer:gradLayer];
    UIButton *backBtn = [UIButton buttonWithImage:@"navBack" selectImage:@"navBack"];
    backBtn.frame = CGRectMake(0, statusBarHeight, 44, 44);
    [backBtn addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [baseView addSubview:backBtn];
    NSString *title = (_datasource && [_datasource isEqualToString:@"dcb"])?@"药球患者管理":@"入院管理";
    UILabel *titleLabel = [UILabel lableWithText:title colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
    titleLabel.frame = CGRectMake(viewPix(100), statusBarHeight, Screen_W-viewPix(200), 44);
    [baseView addSubview:titleLabel];
    UIButton *searchBtn = [UIButton buttonWithTitle:@"输入患者关键信息搜索" titleFont:LGFont(15) textColor:@"#999999" imageName:@"searchGray16"];
    searchBtn.frame = CGRectMake(viewPix(12), topBarHeight+viewPix(6), Screen_W-viewPix(24), viewPix(32));
    searchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    searchBtn.imageEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, 0);
    searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(20), 0, 0);
    searchBtn.backgroundColor = [UIColor colorWithString:@"#F3F3F3"];
    searchBtn.cornerRidus = 5;
    [searchBtn addTarget:self action:@selector(searchPatientAction) forControlEvents:UIControlEventTouchUpInside];
    [baseView addSubview:searchBtn];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
